package i_Inst;

import mips.Decoder;
import mips.Memory;
import mips.PC;
import mips.Register;



public class SW  {
	
	public static void sw(int RegisterSource,int RegisterDest ,int offset){
	
int dest = offset + (Register.registers[RegisterDest]);
Integer source = Register.registers[RegisterSource];

         Memory.dataMemory.set(dest,source);
         
         System.out.println("PC value now is : " +Decoder.toBinary(PC.pc)); 
 		
 		System.out.println("PC value :"+ Decoder.toBinary(PC.pc)+" sent to The instruction memory to read address..");
 		
 		System.out.println("Instuction memory sending Instruction[31:26] to CONTROL,Instruction[31:26] having : "+ "101011");
 		System.out.println("Instuction memory sending Instruction[25:21] : "+Decoder.AddzerostoLeft(Decoder.toBinary(RegisterSource)+"",5)+" to Registers @ read Register1");
 		System.out.println("The mux have selected 0 beacause control unit 'RegDst equal 0'");
 		System.out.println("Instuction memory sending Instruction[20:16] : "+Decoder.AddzerostoLeft(Decoder.toBinary(RegisterDest)+"",5)+" to Registers @ read Register2");
 	
 		System.out.println("Register number  read now is : " + Decoder.AddzerostoLeft(Decoder.toBinary(RegisterSource)+"",5));
 		System.out.println("Register number 2 read  is : " + Decoder.AddzerostoLeft(Decoder.toBinary(RegisterDest)+"",5));
 		
 		System.out.println("CONTROL send ALUOP(Add)  to ALU CONTROL");
 		
 		System.out.println("Instuction memory sending Instruction[15:0] " +Decoder.AddzerostoLeft(Decoder.toBinary(offset)+"",16)+" to Sign Extend...");
 		System.out.println("The constant after Sign Extend: " + Decoder.AddzerostoLeft(Decoder.toBinary(offset)+"",32));
 		
 		System.out.println("CONTROL send ALUSrc of 01 to mux and selected 1");
 		
 		System.out.println("CONTROL send RegWrite of 0 to Register");
 		System.out.println("Registers sends first source value : "+ Decoder.toBinary(RegisterSource) + " Second Source value from mux : " + Decoder.AddzerostoLeft(Decoder.toBinary(offset)+"",32) + "  to ALU");
 		System.out.println("ALU is doing the add content of register  to offset operating now...");
 		System.out.println("offset + register value : " + Decoder.toBinary(dest) + " is went to Data Memory @address");
 		System.out.println("Data memory sent the data to be written to data mememory :" +Decoder.toBinary(source));
 		
 		System.out.println("CONTROL send MemWrite of 1 to Datamemory");
 	
 		System.out.println("PC value sent to Add");
 		PC.pc +=4;
 		System.out.println("pc value now is incremented by 4 and passed to the mux :"+Decoder.toBinary(PC.pc)+",selection 0 occured");
 		System.out.println("Mux sent back to PC");
 		System.out.println("New value of PC now is : " + Decoder.toBinary(PC.pc));
 	
       
		}

}

